<!DOCTYPE html>
<html lang="zh-CN"><head>
<title>评论列表</title>
<meta charset="utf-8">
<meta content="" name="description">
<meta content="" name="keywords">
<meta content="eric.wu" name="author">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="no-cache,must-revalidate" http-equiv="Cache-Control">
<meta content="no-cache" http-equiv="pragma">
<meta content="0" http-equiv="expires">
<meta content="telephone=no, address=no" name="format-detection">
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<link rel="stylesheet" type="text/css" href="/sources/css/main.css">
<link rel="stylesheet" type="text/css" href="/sources/css/dialog.css">
<script src="/sources/js/jquery_min.js"></script>
<script src="/sources/js/main.js"></script>
<script src="/sources/js/dialog_min.js"></script>
<style>
.nav_footer>ul a.a_collect.on{
    color: #ff0000;
}
.nav_footer>ul a.on span.icons_love {
background-position: center -608px;
}

.list_article>article>section>*{
    padding-left:10px;
    padding-right:10px;
}
</style>
<script>
    function delComment(thi ,app_id, tid, cid, uid, ruid){
        alert('确定删除："'+thi.parentNode.innerText.slice(0, 7)+'..."吗？',null, function(){
            loading(true);
            var req = {
                "app_id" : app_id,
                "tid" : tid,
                "cid" : cid,
                "uid" : uid,
                "ruid": ruid
            }
            $.ajax({
                url: "{$site_info.route_base}/index/deletecomment",
                type:"post",
                data:req,
                dataType:"JSON",
                success: function(res){
                    loading(false);
                    if(1 == res.result){
                        $(thi).closest("li").remove();
                        location.reload();
                    }else{
                        alert(res.message||"失败", 1500);
                    }
                },
                error: function(){
                    loading(false);
                    alert("删除失败", 1500);
                }
            });
        }, function(){});
    }


    function userOperate(thi, evt, typ, id){
        var n = -1;
        if(thi.classList.contains("on") ){
            n = 1;
        }
        var obj = {
            userId: 123334,
            type:typ,// collect, like
            n:n
        }
        loading(true);
        $.ajax({
            url: "data/userOperate.json",
            type:"post",
            data:obj,
            dataType:"JSON",
            success: function(res){
                loading(false);
                if(1 == res.result){
                    //thi.querySelector("label").innerHTML = res.data.total;
                    thi.classList[n>0?"remove":"add"]("on");
                }else{
                    alert(res.message||"失败", 1500, function(){});
                }
            }
        });

    }

    function showOperate(type, thi, evt){
        var pop_operate = document.getElementById("pop_operate");
        if(type){
            var btns = thi.innerHTML;
            pop_operate.querySelectorAll("div.pop_container")[0].innerHTML = btns;
            pop_operate.classList.add("on");
        }else{
            pop_operate.classList.remove("on");
        }
    }


    
    function loadMore(app_id, tid, uid, page){
        if(page == 1) { page = 2; }
        else page = page+1;
        var req = {
            "app_id" : app_id,
            "tid" : tid,
            'uid' : uid,
            "page": page,
        }
        loading(true);
        $.ajax({
            url: "{$site_info.route_base}/ajax/ajaxcomments",
            type:"post",
            data:req,
            dataType:"text",
            success: function(res){
                $('#list_comment').append(res);
                loading(false);
            },
            error:function(){
                loading(false);
            }
        });

        
    }
   function collectTrends(type, app_id, tid, uid){
       var args = arguments;
        loading(true);
        $.post('{$site_info.route_base}/index/collect',{
            "type" : type,
            "app_id"  : app_id,
            "tid"  : tid,
            "uid"  : uid,
            },function(res){
                loading(false);
                if("1" == res){
                    var $a = $("#collect_001");
                    var label = $a.find("label")[0];
                    var total = parseInt(label.innerText );
                    $("#collect_001, #collect_002")[0==type?"addClass":"removeClass"]("a_collect on");
                    total = (0 == type)?total+1:total-1;
                    label.innerText = total;
                    $("#collect_001, #collect_002").attr("onclick", 'collectTrends('+[1,0][type]+","+(Array.prototype.slice.call(args, 1).join(','))+');');
                }
            });
    }
    function praiseTrends(type, app_id, tid, uid){
        var args = arguments;
        loading(true);
        $.post('{$site_info.route_base}/index/praise',{
            "type" : type,
            "app_id"  : app_id,
            "tid"  : tid,
            "uid"  : uid,
            },function(res){
                loading(false);
                if("1" == res){
                    var $a = $("#praise_001");
                    var label = $a.find("label")[0];
                    var total = parseInt(label.innerText );
                    $("#praise_001, #praise_002")[0==type?"addClass":"removeClass"]("on");
                    total = (0 == type)?total+1:total-1;
                    label.innerText = total;
                    $("#praise_001, #praise_002").attr("onclick", 'praiseTrends('+[1,0][type]+","+(Array.prototype.slice.call(args, 1).join(','))+');');
                }
            });
    }
    //type(0可赞，1已赞),app_id(应用id),tid(帖子id),cid(评论id),uid(用户id)
    function commentPraise(type,app_id,tid,cid,uid) {
        var args = arguments;
        loading(true);
        $.post('{$site_info.route_base}/index/commentpraise',{
            "type" : type,
            "app_id"  : app_id,
            "tid"  : tid,
            "cid"  : cid,
            "uid"  : uid,
        },function(res){
            loading(false);
            if("1" == res){
                var label = $("#praise_"+cid)[0];
                var total = parseInt(label.innerText );
                total = (0 == type)?total+1:total-1;
                label.innerText = total;
                $("#cid_"+cid).attr("href", 'javascript:commentPraise('+[1,0][type]+","+(Array.prototype.slice.call(args, 1).join(','))+');')[0].innerText = [ "取消赞", "赞"][type];
            }
        });        
   }
</script>
</head>
<body onselectstart="return true;" ondragstart="return false;" class="discuss_detail">
	<div id="container" class="container">
	    <header></header>
	    <div class="body pt_5">
	        <div id="" class="list_article">
	            <article>
	                <section>
	                        <h5>{$post_data.title}</h5>
	                        <h6>
	                            <small>{$post_data.publish_time|date="Y-m-d H:i:s",###}</small>
	                        </h6>
	                        <div>{$post_data.intro}</div>
	                </section>
	                <footer>
	                    <ul class="box">
	                        <li>
	                            <a href="javascript:;" class="a_collect">
	                                <span class="number"><label>{$post_data.comment_count}</label></span>评论
	                            </a>
	                        </li>
	                        <li>
	                            <a href="javascript:;" class="a_like <notempty name='post_data.is_like'>on</notempty>" id="praise_{$post_data.id}" onclick="praiseTrends({$post_data.is_like}, {$site_info.app_id}, {$post_data.id}, {$user_info.user_id});">
	                               <span class="icons icons_like">&nbsp;</span>
	                               <label>{$post_data.like}</label>
	                            </a>
	                        </li>
	                        <li>
	                            <a href="javascript:;" class="a_collect <notempty name='post_data.is_laud'>on</notempty>" id="collect_{$post_data.id}" onclick="collectTrends({$post_data.is_laud}, {$site_info.app_id}, {$post_data.id}, {$user_info.user_id});">
	                               <span class="icons icons_collect">&nbsp;</span>
	                               <label>{$post_data.laud}</label>
	                            </a>
	                        </li>
	                    </ul>
	                </footer>
	            </article>
	        </div>
	
	        <div>
	            <ul id="list_comment" class="list_comment">
	            
                    <foreach name="comment_list" item="vo"> 
	                <li>
	                    <dl class="tbox">
	                        <dd>
	                            <span class="head_img">
	                               <img src="{$vo.user_info.user_pic}" onerror="this.src='{$default_info.default_head}';">
	                            </span>
	                        </dd>
	                        <dd>
	                            <h7>{$vo.user_info.nick}</h7>
	                            <p>{$vo.content}<span class="icons icons_del" onclick="delComment(this, {$site_info.app_id}, {$post_data.id}, {$vo.comment_id}, {$vo.user_info.user_id}, {$vo.user_info.user_id});">&nbsp;</span></p>
	                            <time>
	                                {$vo.comment_time|date="Y-m-d H:i:s",###}
	                                <span>赞 <label id="praise_{$vo.comment_id}">{$vo.laud_count|default=0}</label></span>
	                            </time>
	                        </dd>
	                        <dd>
	                            <span class="icons icons_op" onclick="showOperate(true, this, event);">
	                                <a href="{$site_info.route_base}/index/commentview/comment_id/{$vo.comment_id}" class="btn">回复</a>
	                                <a href="javascript:commentPraise({$vo.is_laud},{$site_info.app_id},{$post_data.id},{$vo.comment_id},{$user_info.user_id});" class="btn" id="cid_{$vo.comment_id}">赞</a>
	                                <a href="javascript:showOperate(false);" class="btn calcel">取消</a>
	                            </span>
	                        </dd>
	                    </dl>
	                </li>
	                </foreach>
	              </ul>
	         </div>
	    </div>
	    <footer>
	        <section class="nav_footer">
	            <ul class="box">
	                <li>
	                    <a href="{$site_info.route_base}/index/index">
	                        <span class="icons_back">&nbsp;</span>
	                        <label>返回</label>
	                    </a>
	                </li>
	                <li>
	                    <a href="{$site_info.route_base}/index/commentview/id/{$post_data.id}">
	                        <span class="icons_comment">&nbsp;</span>
	                        <label>评论</label>
	                    </a>
	                </li>
	                <li>
	                    <a href="javascript:;" class="<empty name='post_data.is_laud'>on</empty>" id="praise_{$post_data.id}" onclick="praiseTrends({$post_data.is_like}, {$site_info.app_id}, {$post_data.id}, {$user_info.user_id});">
	                       <span class="icons_like">&nbsp;</span>
	                       <label>赞</label>
	                    </a>
	                </li>
	                <li>
	                    <a href="javascript:;" class="<empty name='post_data.is_like'>on</empty>" id="collect_{$post_data.id}" onclick="collectTrends({$post_data.is_like}, {$site_info.app_id}, {$post_data.id}, {$user_info.user_id});">
	                        <span class="icons_love">&nbsp;</span>
	                        <label>喜欢</label>
	                    </a>
	                </li>
	            </ul>
	        </section>
	    </footer>
	</div>

    <section id="pop_operate" class="pop_operate">
        <div class="pop_container" onclick="showOperate(false);">
            <a href="javascript:;" class="btn">回复</a>
            <a href="javascript:;" class="btn">赞</a>
            <a href="javascript:showOperate(false);" class="btn calcel">取消</a>
        </div>
        <div class="pop_masker"></div>
    </section>
<script>
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    WeixinJSBridge.call('showOptionMenu');
});
</script>
</body>
</html>